<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - 智能竞赛信息平台</title>
    <!-- 网站图标 -->
    <link rel="icon" type="image/x-icon" href="{{ url_for('static', filename='favicon.ico') }}">
    <link rel="shortcut icon" type="image/x-icon" href="{{ url_for('static', filename='favicon.ico') }}">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/base.css') }}">
    <!-- 使用国内CDN -->
    <script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/iconify/1.0.7/iconify-icon.min.js"></script>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: #F8FAFC;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .login-container {
            min-height: 100vh;
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            padding: 16px;
            position: relative;
            overflow: hidden;
        }

        .login-container::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="white" opacity="0.1"/><circle cx="75" cy="75" r="1" fill="white" opacity="0.1"/><circle cx="50" cy="10" r="0.5" fill="white" opacity="0.1"/><circle cx="10" cy="60" r="0.5" fill="white" opacity="0.1"/><circle cx="90" cy="40" r="0.5" fill="white" opacity="0.1"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
            pointer-events: none;
        }

        .login-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
            padding: 40px;
            width: 100%;
            max-width: 380px;
            position: relative;
            z-index: 1;
            border: 1px solid rgba(255, 255, 255, 0.2);
            animation: fadeInUp 0.6s ease-out;
            margin: auto;
        }

        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .login-header {
            text-align: center;
            margin-bottom: 32px;
        }

        .login-logo {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 12px;
            margin-bottom: 20px;
        }

        .login-title {
            font-size: 28px;
            font-weight: 700;
            background: linear-gradient(135deg, #2A5CAA, #1e4788);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            margin: 0 0 8px 0;
        }

        .login-subtitle {
            font-size: 14px;
            color: #6B7280;
            margin: 0;
        }

        .login-form {
            display: flex;
            flex-direction: column;
            gap: 20px;
        }

        .form-group {
            display: flex;
            flex-direction: column;
            gap: 8px;
            position: relative;
        }

        .form-label {
            font-size: 14px;
            font-weight: 600;
            color: #374151;
            display: flex;
            align-items: center;
            gap: 6px;
        }

        .form-input {
            padding: 12px 14px;
            border: 2px solid #E5E7EB;
            border-radius: 12px;
            font-size: 14px;
            transition: all 0.3s ease;
            background: rgba(255, 255, 255, 0.8);
        }

        .form-input:focus {
            outline: none;
            border-color: #2A5CAA;
            box-shadow: 0 0 0 4px rgba(42, 92, 170, 0.1);
            background: white;
        }

        .form-input:hover {
            border-color: #9CA3AF;
        }

        .form-input.with-icon {
            padding-left: 40px;
        }

        .input-icon {
            position: absolute;
            left: 12px;
            top: 50%;
            transform: translateY(-50%);
            color: #9CA3AF;
            z-index: 1;
        }

        .password-toggle {
            position: absolute;
            right: 12px;
            top: 50%;
            transform: translateY(-50%);
            background: none;
            border: none;
            color: #9CA3AF;
            cursor: pointer;
            padding: 4px;
            border-radius: 4px;
            transition: color 0.2s;
        }

        .password-toggle:hover {
            color: #6B7280;
        }

        .login-btn {
            background: linear-gradient(135deg, #2A5CAA, #1e4788);
            color: white;
            border: none;
            padding: 14px 20px;
            border-radius: 12px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-top: 8px;
            position: relative;
            overflow: hidden;
        }

        .login-btn::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
            transition: left 0.5s;
        }

        .login-btn:hover::before {
            left: 100%;
        }

        .login-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 12px 24px rgba(42, 92, 170, 0.3);
        }

        .login-btn:active {
            transform: translateY(0);
        }

        .login-btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
        }

        .error-message {
            background: linear-gradient(135deg, #FEE2E2, #FECACA);
            color: #DC2626;
            padding: 14px 16px;
            border-radius: 12px;
            font-size: 14px;
            margin-bottom: 16px;
            display: none;
            border: 1px solid #FCA5A5;
            box-shadow: 0 2px 8px rgba(220, 38, 38, 0.1);
        }

        .demo-info {
            background: linear-gradient(135deg, #F0F9FF, #E0F2FE);
            border: 1px solid #BAE6FD;
            border-radius: 12px;
            padding: 16px;
            margin-bottom: 24px;
            position: relative;
            overflow: hidden;
        }

        .demo-info::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 3px;
            background: linear-gradient(90deg, #0369A1, #0EA5E9, #38BDF8);
        }

        .demo-info h4 {
            margin: 0 0 8px 0;
            color: #0369A1;
            font-size: 14px;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 6px;
        }

        .demo-info p {
            margin: 0;
            font-size: 13px;
            color: #0C4A6E;
            line-height: 1.5;
        }

        .register-link {
            text-align: center;
            margin-top: 24px;
            font-size: 14px;
            color: #6B7280;
        }

        .register-link a {
            color: #2A5CAA;
            text-decoration: none;
            font-weight: 600;
            transition: all 0.2s;
        }

        .register-link a:hover {
            color: #1e4788;
            text-decoration: underline;
        }

        .features {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 12px;
            margin-top: 24px;
            padding-top: 24px;
            border-top: 1px solid #E5E7EB;
        }

        .feature {
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 12px;
            color: #6B7280;
        }

        .feature-icon {
            color: #2A5CAA;
        }

        /* 响应式设计 */
        @media (max-width: 480px) {
            .login-card {
                padding: 28px 20px;
                margin: 12px;
                max-width: calc(100% - 24px);
            }
            
            .features {
                grid-template-columns: 1fr;
            }
            
            .login-title {
                font-size: 24px;
            }
        }

        /* 电脑端优化 */
        @media (min-width: 768px) {
            .login-card {
                max-width: 420px;
                padding: 48px;
            }
            
            .login-title {
                font-size: 32px;
            }
            
            .login-subtitle {
                font-size: 16px;
            }
            
            .form-input {
                padding: 14px 16px;
                font-size: 15px;
            }
            
            .login-btn {
                padding: 16px 24px;
                font-size: 16px;
            }
        }

        /* 大屏幕优化 */
        @media (min-width: 1200px) {
            .login-card {
                max-width: 460px;
                padding: 56px;
            }
            
            .login-title {
                font-size: 36px;
            }
        }
    </style>
</head>
<body>
    <div class="login-container">
        <div class="login-card">
            <div class="login-header">
                <div class="login-logo">
                    <iconify-icon icon="clarity:computer-solid" style="color: #2A5CAA;" width="40"></iconify-icon>
                    <span style="font-size: 28px; font-weight: 700; color: #2A5CAA;">竞赛智汇</span>
                </div>
                <h1 class="login-title">欢迎回来</h1>
                <p class="login-subtitle">登录您的账户，开启竞赛之旅</p>
            </div>

            <div class="demo-info">
                <h4>
                    <iconify-icon icon="material-symbols:info" width="16"></iconify-icon>
                    演示账户
                </h4>
                <p>学号: <strong>202400120001</strong><br>密码: <strong>123456</strong></p>
            </div>

            <div class="error-message" id="errorMessage"></div>

            <form class="login-form" id="loginForm">
                <div class="form-group">
                    <label class="form-label" for="studentId">
                        <iconify-icon icon="material-symbols:school" width="16"></iconify-icon>
                        学号
                    </label>
                    <div style="position: relative;">
                        <iconify-icon icon="material-symbols:person" class="input-icon" width="20"></iconify-icon>
                        <input type="text" id="studentId" name="student_id" class="form-input with-icon" 
                               placeholder="请输入您的学号" required>
                    </div>
                </div>

                <div class="form-group">
                    <label class="form-label" for="password">
                        <iconify-icon icon="material-symbols:lock" width="16"></iconify-icon>
                        密码
                    </label>
                    <div style="position: relative;">
                        <iconify-icon icon="material-symbols:lock-outline" class="input-icon" width="20"></iconify-icon>
                        <input type="password" id="password" name="password" class="form-input with-icon" 
                               placeholder="请输入您的密码" required>
                        <button type="button" class="password-toggle" id="passwordToggle">
                            <iconify-icon icon="material-symbols:visibility" width="20"></iconify-icon>
                        </button>
                    </div>
                </div>

                <button type="submit" class="login-btn" id="loginBtn">
                    <span id="loginText">登录</span>
                    <span id="loadingText" style="display: none;">登录中...</span>
                </button>
            </form>

            <div class="register-link">
                还没有账户？<a href="/register">立即注册</a>
            </div>

            <div class="features">
                <div class="feature">
                    <iconify-icon icon="material-symbols:security" class="feature-icon" width="16"></iconify-icon>
                    安全可靠
                </div>
                <div class="feature">
                    <iconify-icon icon="material-symbols:speed" class="feature-icon" width="16"></iconify-icon>
                    快速响应
                </div>
                <div class="feature">
                    <iconify-icon icon="material-symbols:update" class="feature-icon" width="16"></iconify-icon>
                    实时更新
                </div>
                <div class="feature">
                    <iconify-icon icon="material-symbols:support-agent" class="feature-icon" width="16"></iconify-icon>
                    AI助手
                </div>
            </div>
        </div>
    </div>

    <script>
        document.getElementById('loginForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const studentId = document.getElementById('studentId').value.trim();
            const password = document.getElementById('password').value.trim();
            const loginBtn = document.getElementById('loginBtn');
            const loginText = document.getElementById('loginText');
            const loadingText = document.getElementById('loadingText');
            const errorMessage = document.getElementById('errorMessage');
            
            if (!studentId || !password) {
                showError('请填写完整的登录信息');
                return;
            }
            
            // 显示加载状态
            loginBtn.disabled = true;
            loginText.style.display = 'none';
            loadingText.style.display = 'inline';
            hideError();
            
            // 发送登录请求
            fetch('/api/login', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify({
                    student_id: studentId,
                    password: password
                })
            })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    // 登录成功，跳转到首页
                    window.location.href = '/';
                } else {
                    showError(data.message || '登录失败，请检查学号和密码');
                }
            })
            .catch(error => {
                console.error('登录错误:', error);
                showError('网络错误，请稍后重试');
            })
            .finally(() => {
                // 恢复按钮状态
                loginBtn.disabled = false;
                loginText.style.display = 'inline';
                loadingText.style.display = 'none';
            });
        });
        
        // 密码显示/隐藏切换
        document.getElementById('passwordToggle').addEventListener('click', function() {
            const passwordInput = document.getElementById('password');
            const icon = this.querySelector('iconify-icon');
            
            if (passwordInput.type === 'password') {
                passwordInput.type = 'text';
                icon.setAttribute('icon', 'material-symbols:visibility-off');
            } else {
                passwordInput.type = 'password';
                icon.setAttribute('icon', 'material-symbols:visibility');
            }
        });
        
        // 回车键登录
        document.getElementById('password').addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                document.getElementById('loginForm').dispatchEvent(new Event('submit'));
            }
        });
        
        function showError(message) {
            const errorMessage = document.getElementById('errorMessage');
            errorMessage.textContent = message;
            errorMessage.style.display = 'block';
        }
        
        function hideError() {
            const errorMessage = document.getElementById('errorMessage');
            errorMessage.style.display = 'none';
        }
    </script>
</body>
</html>
